﻿CREATE TRIGGER [dbo].[TR_User_Delete]
	ON [dbo].[User]
	INSTEAD OF DELETE
	AS
	BEGIN
		SET NOCOUNT ON
		-- Delete the folders before deleting the user
		DELETE FROM [dbo].[Folder]
		WHERE [UserId] IN (SELECT [Id] FROM deleted);
		-- Delete the user
		DELETE FROM [dbo].[User]
		WHERE [Id] IN (SELECT [Id] FROM deleted);
	END
